package com.demo.project_template.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.demo.project_template.entity.UserGift;
import com.demo.project_template.service.UserGiftService;
import com.demo.project_template.vo.response.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杨玉龙
 * @since 2024-08-21 11:53:54
 */
@Api(tags = "用户礼物")
@RestController
@RequestMapping("/userGift")
public class UserGiftController {
    @Resource
    private UserGiftService userGiftService;

    @ApiOperation(value = "查询用户礼物列表")
    @GetMapping(value = "/listUserGift")
    public R<List<UserGift>> listUserGift(@RequestParam Long userId,@RequestParam(required = false) Integer limit){
        List<UserGift> userGifts = userGiftService.list(new LambdaQueryWrapper<UserGift>()
                .eq(UserGift::getUserId, userId)
                .last("limit " + limit));
        return R.success(userGifts);
    }

    @ApiOperation(value = "送礼物")
    @PostMapping(value = "/sendGift")
    public R<?> sendGift(@RequestBody UserGift userGift){
        userGiftService.sendGift(userGift);
        return R.success();
    }
}
